var status = 0;
var choice="";
var itemarr= Array(
	Array("3064430","50000"),
	Array("3064431","50000"),
	Array("5062800","6000"),
	Array("5062000","5000"),
	Array("5062002","9000"),
	Array("5062009","1100"),
	Array("5062010","13000"),
	Array("5062024","18000"),
	Array("5062005","15000"),
	Array("5062090","14500"),
	Array("5062500","13000"),
	Array("5062503","14500"),
	Array("5750002","8000"),
	Array("5530269","28000"),
	Array("5530111","28000"),
	Array("5530342","35000"),
	Array("5530341","35000"),
	Array("5530360","30000"),
	Array("2049762","35000")
);
function start() {
	status =  - 1;
	action(1, 0, 0);
}

function action(mode, type, selection) {
	if (mode ==  - 1)
		cm.dispose();
	else {
		if (status == 0 && mode == 0) {
			cm.dispose();
			return;
		} else if (status >= 1 && mode == 0) {
			cm.sendOk("真的不考虑购买一些东西么？好的,欢迎下次继续光临！");
			cm.dispose();
			return;
		}
		if (mode == 1)
			status++;
		else
			status--;
		if (status == 0) {
			choices = "请选择您要购买的道具  #rPS：购买前请确认背包有足够的空间。\r\n#r#e #n#b";
			for (var i = 0; i < itemarr.length; i++) {
				choices += "\r\n#b#L" + i + "##v" + itemarr[i][0] + "##z" + itemarr[i][0] + "#　#d需要#r" + itemarr[i][1] + "#d点卷#k#l";
			}
			cm.sendSimpleS("" + choices, 2);
		} else if (status == 1) {
			cm.sendGetNumber("你选择的商品为#b#v" + itemarr[selection][0] + "#售价为：" + itemarr[selection][1] + "点卷/张\r\n请输入你购买的数量", 1, 1, cm.getPlayer().getCSPoints(1));
			choice = selection;
		} else if (status == 2) {
			fee = selection;
			money = fee * itemarr[choice][1];
			if (fee < 0) {
				cm.sendOk("不能输入0.或者你没有足够的点卷支付你要买的数量.!");
				cm.dispose();
			} else if (cm.getPlayer().getCSPoints(1) < money) {
				cm.sendOk("购买失败，你没有" + money + "点卷");
				cm.dispose();
            } else if (cm.getSpace(1) < 3 || cm.getSpace(2) < 3 || cm.getSpace(3) < 3 || cm.getSpace(4) < 3 || cm.getSpace(5) < 3) {
                cm.sendOk("您的背包空间不足，请保证每个栏位至少3格的空间，以避免失败。");
                cm.dispose();
			} else {
				cm.gainNX( - money);
				cm.gainItem(itemarr[choice][0], fee);
				cm.worldSpouseMessage(0x0F, "[点卷商城] :玩家:" + "[" + cm.getChar().getName() + "]" + " " + "在" + cm.getServerName() + "点卷商城潜能魔方区进行了赞助消费.");
				cm.sendOk("恭喜，购买成功。您的每一次赞助消费我们都很感激！");
				cm.dispose();
			}
		}
	}
}
